package geograph.china;

import java.util.ArrayList;
import java.util.List;

/**
 * Title:
 * Created by Myth on 2017/8/17.
 */
public class Province {

    private String provinceName;;
    private String provinceEnglishName;
    private List<City> cityList;

    public Province(String provinceName, String provinceEnglishName) {
        this.provinceName = provinceName;
        this.provinceEnglishName = provinceEnglishName;
        cityList = new ArrayList<>();
    }

    public String getProvinceEnglishName() {
        return provinceEnglishName;
    }

    public List<City> getCityList() {
        return cityList;
    }

    public City searchCity(String englishName) {
        for (City city : cityList) {
            if (city.getCityEnglishName().equals(englishName))
                return city;
        }
        return null;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Province province = (Province) o;

        if (provinceName != null ? !provinceName.equals(province.provinceName) : province.provinceName != null)
            return false;
        return provinceEnglishName != null ? provinceEnglishName.equals(province.provinceEnglishName) : province.provinceEnglishName == null;
    }

    @Override
    public int hashCode() {
        int result = provinceName.hashCode();
        result = 31 * result + provinceEnglishName.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "{\"name\":\"" + provinceName +"\", \"english_name\":\"" + provinceEnglishName + "\"}";
    }
}

